<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container" style="margin-bottom:20px">
      <span style="margin-left:10px">标题：</span>
      <el-input @keyup.enter.native="handleFilter" class="filter-item widht" placeholder="请输入关键字"
        v-model="listQuery.keyWord" clearable>
      </el-input>
      <span style="margin-left:10px">资讯栏目：</span>
      <el-cascader change-on-select clearable placeholder="请选择" expand-trigger="click" :options="sections"
        v-model="sectionIds" class="widht"></el-cascader>
      <span style="margin-left:10px">发布日期：</span>
      <el-date-picker class="timeWidht" v-model="dateformat" type="daterange" align="right" unlink-panels
        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss"
        :picker-options="pickerOptions">
      </el-date-picker>
      <span style="margin-left:10px">投放平台：</span>
      <el-select v-model="platform" placeholder="请选择" clearable>
        <el-option v-for="item in platOptions" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      </el-date-picker>
      <br><br>
      <span style="margin-left:10px">作者：</span>
      <el-input v-model="listQuery.authorName" class="widht" placeholder="请输入资讯作者" clearable></el-input>
      <span style="margin-left:10px">资讯标签：</span>
      <el-select class="widht" v-model="listQuery.labelId" clearable filterable remote reserve-keyword
        placeholder="请输入标签" :remote-method="getInfoLabels">
        <el-option v-for="item in labels" :key="item.id" :label="item.name" :value="item.id">
        </el-option>
      </el-select>
      <span style="margin-left:10px">投放区域：</span>
      <el-select v-model="listQuery.provinceId" placeholder="请选择" clearable>
        <el-option v-for="item in areaOptions" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      <span style="margin-left:10px">广告：</span>
      <el-select v-model="listQuery.isAd" placeholder="请选择" style="width: 120px;" clearable>
        <el-option label="是" :value='1'></el-option>
        <el-option label="否" :value='0'></el-option>
      </el-select>
      <span style="margin-left:10px">热点推荐：</span>
      <el-select v-model="listQuery.recommend" placeholder="请选择" style="width: 120px;" clearable>
        <el-option label="是" :value='1'></el-option>
        <el-option label="否" :value='0'></el-option>
      </el-select>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-search"
        @click="handleFilter">搜索</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" @click="handleAllDelete" :type="pageBoolean.delColor"
        icon="el-icon-delete">{{ pageBoolean.delText }}</el-button>
    </div>

    <el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="数据加载中，请稍后" border fit
      highlight-current-row :default-sort="{prop: 'inTime', order: 'descending'}"
      @selection-change="handleSelectionChange" @sort-change="getSortList" style="width: 100%">
      <el-table-column v-if='showAllDel' type="selection" width="55">
      </el-table-column>

      <el-table-column align="center" label="ID" min-width="60">
        <template slot-scope="scope">
          <span class="link-type">{{scope.row.id}}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="110" align="center" label="标题" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{scope.row.title}}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="80" align="center" label="所属栏目" show-overflow-tooltip prop="curSectionName">
      </el-table-column>
      <el-table-column min-width="80" align="center" label="作者" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{scope.row.authorName}}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="110" align="center" label="标签" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{scope.row.labelNames}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="投放区域" min-width="95" prop="provinceNames" show-overflow-tooltip>
      </el-table-column>
      <el-table-column align="center" label="投放平台" min-width="95" prop="" show-overflow-tooltip>
        <template slot-scope="scope">
          <span class="link-type">{{getPlat(scope.row.publishPlatform)}}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="140" align="center" label="发布日期" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.inTime | dateformat('YYYY-MM-DD HH:mm') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="权重" min-width="95" sortable="custom" prop="weight"></el-table-column>
      <el-table-column min-width="80" align="center" label="审核人" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{scope.row.auditName ? scope.row.auditName : scope.row.authorName}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="阅读数" min-width="80" sortable="custom" prop="view"></el-table-column>
      <el-table-column align="center" label="点赞数" min-width="80" sortable="custom" prop="likeCount"></el-table-column>
      <el-table-column align="center" label="AD（广告）" min-width="80">
        <template slot-scope="scope">
          <span>{{scope.row.isAd == 1 ? "是" : "否"}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="热点推荐" min-width="80">
        <template slot-scope="scope">
          <span>{{scope.row.recommend == 1 ? "是" : "否"}}</span>
        </template>
      </el-table-column>


      <el-table-column align="center" label="操作" min-width="200">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="handleWatchNotes(scope.row.id)">查看评论</el-button>
          <el-button size="small" @click="handleModifyStatus(scope.row)">编辑
          </el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div v-show="!listLoading" class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page.sync="listQuery.pageNo" :page-sizes="[10,20,30,50]" :page-size="listQuery.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>

    <el-dialog top="4%" width="70%" title="编辑页" :visible.sync="dialogFormVisible" :before-close="handleClose">
      <el-form :rules="rules" ref="dataForm" :model="temp" label-position="right" label-width="100px"
        style='width: 70%; margin-left:50px;'>
        <el-form-item label="所属栏目：">
          <el-cascader change-on-select placeholder="请选择" expand-trigger="click" :options="sections"
            v-model="temp.sectionIds"></el-cascader>
        </el-form-item>
        <el-form-item label="标题：" prop="title">
          <el-input type="textarea" maxlength="100" :autosize="{ minRows: 2, maxRows: 4}" v-model="temp.title">
          </el-input>
        </el-form-item>
        <el-form-item label="是否为广告：">
          <el-radio-group v-model="temp.isAd">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否为热点推荐：">
          <el-radio-group v-model="temp.recommend">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="推送平台" prop="platform">
          <multiselect style="line-height:initial" v-model="temp.publishPlatform" :options="plat" placeholder="选择平台"
            selectLabel="选择" :multiple="true" deselectLabel="删除" track-by="value" label="label">
          </multiselect>
          <span>注:如果选择了全平台,则只显示全平台</span>
        </el-form-item>
        <el-form-item label="上传封面：">
          <el-upload style="margin-left:10px" :headers="headers" action="/tools/oss/upload" :on-preview="handlePreview"
            :on-remove="handleRemove" :on-success="handleUploadSuccess" list-type="picture" :file-list="temp.file"
            :limit="2" :accept="'.png,.jpg,.jpeg,.gif'">
            <el-button size="small" type="primary">上传封面</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="标签：">
          <multiselect style="line-height:initial" v-model="temp.labels" :options="labels"
            @search-change="getInfoLabels" placeholder="搜索标签" selectLabel="选择" :multiple="true" deselectLabel="删除"
            track-by="id" :internalSearch="false" label="name">
            <span slot='noResult'>无搜索结果</span>
          </multiselect>
          <!-- <el-tag :key="index" v-for="(tag , index) in temp.labels" closable :disable-transitions="false" @close="handleClose(tag)" type="info">
            {{tag}}
          </el-tag> -->
          <el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small"
            @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
          </el-input>
          <!-- <el-button v-if="temp.labels.length != 5" class="button-new-tag" size="small" @click="showInput">新建标签</el-button> -->
        </el-form-item>
        <el-form-item label-width="110px" label="投放区域：" class="postInfo-container-item">
          <multiselect style="line-height:initial" v-model="temp.areaVal" :options="areaOptions" placeholder="选择区域"
            selectLabel="选择" :multiple="true" deselectLabel="删除" track-by="value" label="label">
          </multiselect>
        </el-form-item>
        <el-form-item label="内容：" prop="content">
          <Tinymce :height=150 ref="editor" v-model="temp.content" :value="temp.content" />
        </el-form-item>
        <el-form-item label="权重：">
          <el-input-number v-model="temp.weight" :step="1"></el-input-number>
        </el-form-item>
        <el-form-item label="浏览数：">
          <el-input-number v-model="temp.view" :step="1"></el-input-number>
        </el-form-item>
        <el-form-item label="点赞数：">
          <el-input-number v-model="temp.likeCount" :step="1"></el-input-number>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="success" @click="handleviewShowClick">预览</el-button>
        <el-button type="primary" @click="updateData" >确定</el-button>
      </div>
    </el-dialog>

    <div class="viewShow">
      <el-dialog :show-close="false" :visible.sync="viewShowDialog">
        <div class="information-cont">
          <h3>{{ temp.title }}</h3>
          <div class="smallLine">
            <span class="time">{{ temp.modifyTime|dateformat('YYYY-MM-DD HH:mm') }}</span>
          </div>
          <div class="artical-cont" v-html="temp.content"></div>
        </div>
      </el-dialog>
    </div>

    <el-dialog top="4%" width="70%" title="查看评论" center :visible.sync="dialogNotesVisible">
      <el-table :key='tableKey' :data="notesList" v-loading="notesListLoading" element-loading-text="数据加载中，请稍后" border
        fit highlight-current-row style="width: 100%">
        <el-table-column v-if='showAllDel' type="selection" width="55">
        </el-table-column>

        <el-table-column align="center" label="评论ID" min-width="60">
          <template slot-scope="scope">
            <span class="link-type">{{scope.row.id}}</span>
          </template>
        </el-table-column>

        <el-table-column min-width="110" align="center" label="评论内容 " show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{scope.row.content}}</span>
          </template>
        </el-table-column>
        <el-table-column min-width="160" align="center" label="评论时间" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.createTime | dateformat('YYYY-MM-DD HH:mm') }}</span>
          </template>
        </el-table-column>

        <el-table-column min-width="110" align="center" label="用户ID" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{scope.row.userId}}</span>
          </template>
        </el-table-column>
        <el-table-column min-width="110" align="center" label="用户昵称" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{scope.row.nickName}}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作" min-width="200">
          <template slot-scope="scope">
            <el-button size="small" type="danger" @click="handleNotesDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div v-show="!notesListLoading" class="pagination-container">
        <el-pagination @size-change="handleSizeNotesChange" @current-change="handleCurrentNotesChange"
          :current-page.sync="notesParams.pageNo" :page-sizes="[5,10,20,30,50]" :page-size="notesParams.pageSize"
          layout="total, sizes, prev, pager, next, jumper" :total="notesTotal">
        </el-pagination>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { getList, delId, delIds, update, getId, getSectionCascade, getInfoLabels, queryInfoCommentByPage, deleteInfoCommentById } from '@/api/advisory'
  import { getToken } from '@/utils/auth' // 验权
  import Tinymce from '@/components/Tinymce'
  import Multiselect from 'vue-multiselect' // 使用的一个多选框组件，element-ui的select不能满足所有需求
  import 'vue-multiselect/dist/vue-multiselect.min.css' // 多选框组件css
  import { getAreaList } from '@/api/activity'
  export default {
    name: 'list',
    components: { Tinymce, Multiselect },
    data() {
      return {
        areaOptions: [],
        platOptions: [
          {
            value: 1,
            label: "全平台"
          },
          {
            value: 2,
            label: "教师端小程序"
          },
          {
            value: 3,
            label: "学生家长端"
          }
        ],
        plat: [
          {
            value: 1,
            label: "全平台"
          },
          {
            value: 2,
            label: "教师端小程序"
          },
          {
            value: 3,
            label: "学生家长端"
          }
        ],
        paltArray: [
          '', '全平台', '教师端小程序','学生家长端'
        ],
        labels: [],
        platFormData:[],
        sections: [],
        sectionIds: [],
        headers: {},
        inputVisible: false,
        inputValue: '',
        brandListOptions: [],
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        dateformat: '',
        platform: null,
        list: null,
        total: null,
        listLoading: true,
        listQuery: {
          keyWord: '',
          sectionId: null,
          labelId: null,
          isAd: null,
          recommend: null,
          provinceId: null,
          pageNo: 1,
          pageSize: 10
        },
        temp: {
          sectionIds: [],
          labels: [],
          isAd: null,
          recommend: null,
          areaVal: [],
          publishPlatform: []
        },
        dialogFormVisible: false,
        rules: {
          title: [{ required: true, message: '标题必填', trigger: 'blur' }],
          'section.name': [{ required: true, message: '所属栏目必填', trigger: 'blur' }],
          'section.tab': [{ required: true, message: '标签必填', trigger: 'blur' }],
          inTime: [{ type: 'date', required: true, message: '发布日期必填', trigger: 'change' }],
          view: [{ required: true, message: '阅读数必填', trigger: 'blur' }],
          platform: [{ required: true, message: '平台必填', trigger: 'blur' }]
        },
        tableKey: 0,
        showAllDel: false,
        multipleSelection: [],
        pageBoolean: {
          delColor: 'primary',
          delText: '批量删除'
        },
        updateButtonStatus: false,

        viewShowDialog: false,

        notesParams: {
          topicId: null,
          pageNo: 1,
          pageSize: 10
        },
        dialogNotesVisible: false,
        notesList: [],
        notesTotal: null,
        notesListLoading: true,

      }
    },
    mounted() {
      this.getSectionCascade()
      this.fetchAreaData()
      this.getInfoLabels('')
      this.getList()
      this.headers = { accessToken: getToken() }
    },
    watch: {
      showAllDel(val) {
        if (val) {
          this.pageBoolean.delText = '选择删除';
          this.pageBoolean.delColor = 'danger';
        } else {
          this.pageBoolean.delText = '批量删除';
          this.pageBoolean.delColor = 'primary';
        }
      },
      multipleSelection(val) {
        if (val.length == 0) {
          this.pageBoolean.delText = '选择删除';
          this.pageBoolean.delColor = 'danger';
        } else {
          this.pageBoolean.delText = '确定删除';
          this.pageBoolean.delColor = 'success';
        }
      },
      // 监控是否选择了“全国” 如果选择了，那么不能选择其他省份
      'temp.areaVal'(e) {
        if (e) {
          if (e.label || e.toString() == []) {
            return
          } else if (e[e.length - 1].label === "全国") {
            this.temp.areaVal = {
              value: 6666,
              label: '全国',
              children: [],
            }
            return
          }
          let flag = false;
          e.forEach(item => {
            if (item.label === '全国') {
              flag = true;
            }
          })
          if (flag) {
            this.temp.areaVal = {
              value: 6666,
              label: '全国',
              children: [],
            }
          }
        }
      },
      // 'temp.publishPlatform'(e) {
      //   var arr = []
      //   for (let i in e) {
      //     arr.push(e[i]); 
      //   }
      //   var allplatform = arr.filter(item => {
      //     return item.value == "1"
      //   })

      //   if (allplatform.length > 0) {
      //     this.temp.publishPlatform = this.plat.find(item => {
      //       return item.value == 1
      //     })
      //   }
      // },
    },
    methods: {
      getPlat(val){
        val = val.split(',')
        var a = ''
          for (var i = 0;i<val.length;i++){
            a += this.paltArray[val[i]] + ','
          }
          var reg=/,$/gi;
          a=a.replace(reg,"")  
          return a
      },
      // 查看评论
      handleWatchNotes(id) {
        this.dialogNotesVisible = true;
        this.getNotesList(id)
      },
      handleNotesDelete(idx, row) {
        const { id } = row;
        this.$confirm('确定要进行删除操作吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteInfoCommentById(id).then(response => {
            const { code } = response
            if (code == 0) {
              this.$notify({
                title: '成功',
                message: '删除评论成功',
                type: 'success',
                duration: 2000
              })
              const index = this.notesList.indexOf(idx)
              this.notesList.splice(idx, 1)
              this.notesTotal--
            } else {
              this.$notify({
                title: '失败',
                message: '删除评论失败',
                type: 'error',
                duration: 2000
              })
            }
          });
        }).catch(() => {
        });

      },
      handleSizeNotesChange(val) {
        this.notesParams.pageSize = val
        this.getNotesList()
      },
      handleCurrentNotesChange(val) {
        this.notesParams.pageNo = val
        this.getNotesList()
      },
      getNotesList(id) {
        id ? this.notesParams.topicId = id : null;
        this.notesListLoading = true;
        queryInfoCommentByPage(this.notesParams).then(res => {
          console.log('res', res);
          this.notesListLoading = false;
          if (res.code == 0) {
            this.notesList = res.data.list;
            this.notesTotal = res.data.total;
          }
        })
      },

      // 查看预览
      handleviewShowClick() {
        this.viewShowDialog = true;
      },
      handleClose() {
        this.$confirm('数据未保存，确认关闭？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.dialogFormVisible = false
        }).catch(() => { });
      },
      // 投放区域
      fetchAreaData() {
        getAreaList().then(response => {
          this.areaOptions = response.data;
          this.areaOptions.unshift({
            value: 6666,
            label: '全国',
            children: [],
          })
        })
      },
      getInfoLabels(title) {
        getInfoLabels({ labelName: title }).then(response => {
          const { code, data } = response
          if (code == 0) {
            this.labels = data;
          }
        })
      },
      getSectionCascade() {
        getSectionCascade().then(response => {
          const { code, data } = response
          if (code == 0) {
            this.sections = data;
          }
        })
      },
      getSortList(filed) {
        let { prop, order } = filed
        let { listQuery } = this
        listQuery['sortField'] = prop
        if (prop) {
          listQuery['sortWay'] = order == 'descending' ? 'DESC' : 'ASC'
        } else {
          listQuery['sortWay'] = null
        }
        this.listQuery = listQuery
        this.getList()
      },
      handleUploadSuccess(rst, file, fileList) {
        let { code, data: { picUrlList } } = rst;
        let { temp } = this;
        if (code == 0) {
          temp['cover'] = picUrlList[0];
          this.temp.file = [{ name: file.url, url: file.url }];
        }
      },
      handlePreview(file) {
      },
      handleRemove(file, fileList) {
        this.temp['cover'] = '';
        this.temp['file'] = [];
      },
      // handleClose(tag) {
      //   this.temp.labels.splice(this.temp.labels.indexOf(tag), 1);
      // },

      showInput() {
        this.inputVisible = true;
        this.$nextTick(_ => {
          this.$refs.saveTagInput.$refs.input.focus();
        });
      },

      handleInputConfirm() {
        let inputValue = this.inputValue;
        if (inputValue) {
          this.temp.labels.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = '';
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      handleAllDelete() {
        let { showAllDel, multipleSelection } = this;
        if (multipleSelection.length != 0) {
          let ids = [];
          multipleSelection.map(e => ids.push(e.id));
          let params = { ids, operateType: 'DELETE' }
          delIds(params).then(response => {
            const { code } = response
            if (code == 0) {
              this.$notify({
                title: '成功',
                message: '批量删除资讯成功',
                type: 'success',
                duration: 2000
              })
              this.handleRefresh();
            } else {
              this.$notify({
                title: '失败',
                message: '批量删除资讯失败',
                type: 'error',
                duration: 2000
              })
            }
          })
        }
        this.showAllDel = !showAllDel;
      },
      getList() {
        this.listLoading = true;
        let params = this.listQuery;
        const { dateformat, sectionIds } = this;
        if (dateformat) {
          params['beginTime'] = dateformat[0];
          params['endTime'] = dateformat[1];
        } else {
          delete params.beginTime;
          delete params.endTime;
        }
        if (sectionIds.length > 0) {
          params['sectionId'] = sectionIds[sectionIds.length - 1]
        } else {
          delete params.sectionId
        }
        if (this.platform) {
          params['publishPlatform'] = this.platform
        } else {
          params['publishPlatform'] = null
        }
        getList(params).then(response => {
          var platformList = response.data.list
          for(var i = 0;i < platformList.length;i++){
            this.platFormData.push(platformList[i].publishPlatform)
          }
         
          const { code, data: { total, list } } = response;
          if (code == 0) {
            this.total = total
            this.list = list
            this.listLoading = false
          }
        });
      },
      handleFilter() {
        this.listQuery.pageNo = 1
        this.getList()
      },
      handleSizeChange(val) {
        this.listQuery.pageSize = val
        this.getList()
      },
      handleCurrentChange(val) {
        this.listQuery.pageNo = val
        this.getList()
      },
      handleModifyStatus(row) {
        getId(row.id).then(response => {
          console.log(response)
          let { code, data } = response;
          let sectionIds = data.sectionIds.split(',');
          data.inTime = new Date(data.inTime)
          /*if (row.labelNames) {
            row.labels = row.labelNames.split(',')
          } else {
            row.labels = []
          }
          data.labels = row.labels*/
  
          data.file = [{ name: data.cover, url: data.cover }]
          sectionIds = sectionIds.map(e => e = parseInt(e))
          data.sectionIds = sectionIds
          data.areaVal = []
          this.temp = data
          for (let i = 0; i < data.provinceIds.length; i++) {
            this.areaOptions.forEach(item => {
              if (item.value === data.provinceIds[i]) {
                this.temp.areaVal.push(item)
              }
            });
          }
          
          var arr = response.data.publishPlatform
          arr = arr.split(',')
          var arrList = []
          var arr1 =[]
          for (var i = 0; i < arr.length; i++) {
            this.plat.forEach(item => {
              if (item.value == arr[i]) {
                arr1.push(item)
                arrList = arr1
              }else if(arr[i] == 1){
                arrList = [{
                  value:1,
                  label:"全平台"
                }]
              }
            })
          }
          this.temp.publishPlatform = arrList
          this.dialogFormVisible = true
        })
      },
      updateData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            let { temp, temp: { sectionIds, labels, content, cover,publishPlatform } } = this;
            if (content.trim().length == 0 || content == '<p><br data-mce-bogus="1"></p>' || content == '<p>&nbsp;</p>' || content == '<p><br></p>') {
              this.$message({
                message: '内容不能为空',
                type: 'error',
                duration: 1000
              });
              this.loading = false;
              return;
            }
            if(publishPlatform.length == 0){
              this.$message({
                message: '请选择平台',
                type: 'error',
                duration: 1000
              });
              return;
            }
            if (cover.length == 0) {
              this.$message({
                message: '请上传封面',
                type: 'error',
                duration: 1000
              });
              this.loading = false;
              return;
            }
           
            if (sectionIds.length > 0) {
              temp.sId = sectionIds[sectionIds.length - 1]
            }
            if (labels.length > 0) {
              let labelArr = []
              labels.map(e => labelArr.push(e.id))
              temp.labels = labelArr
            }

            if (this.temp.areaVal.length === 0) {
              temp['provinceIds'] = [6666]
            } else {
              if (this.temp.areaVal.value == 6666) {
                temp['provinceIds'] = [6666]
              } else {
                temp['provinceIds'] = []
                this.temp.areaVal.forEach(item => {
                  temp['provinceIds'].push(item.value)
                });
              }
            }
            var str = ''
            if (this.temp.publishPlatform) {
              let labels = []
              this.temp.publishPlatform.map((item) => {
                labels.push(item.value)
              })
              for (var i = 0; i < labels.length; i++) {
                if (labels[i] == 1 && labels.length > 1) {
                  console.log(11)
                  temp['publishPlatform'] = '1'
                  break
                } else if (labels[i] != 1 && labels.length > 1) {
                  str += labels[i].toString()
                  temp['publishPlatform'] = str.split('').join(',')
                } else {
                  temp['publishPlatform'] = labels[i] + ''
                }
              }
            } 

            update(temp).then(response => {

              let { code, message } = response
              temp.labels = labels
              if (code == 0) {
                /*this.list.map((e, i) => {
                  if (e.id === temp.id) {
                    temp['labelNames'] = temp['labels'].join(',')
                    temp['section'] = this.brandListOptions.filter(e => e.id == temp['sId'])[0]
                    this.list.splice(i, 1, temp)
                  }
                })*/
                this.getList();
                this.dialogFormVisible = false
                this.$notify({
                  title: '成功',
                  message: '更新成功',
                  type: 'success',
                  duration: 2000
                })
              } else {
                this.$message({
                  title: '失败',
                  message: message,
                  type: 'error',
                  duration: 2000
                })
              }
            }).catch(err => { })
              .finally(() => {
                this.updateButtonStatus = false
              })
          }
        })
      },
      handleDelete(idx, row) {
        const { id } = row;
        this.$confirm('确定要进行删除操作吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delId(id).then(response => {
            const { code } = response
            if (code == 0) {
              this.$notify({
                title: '成功',
                message: '删除资讯成功',
                type: 'success',
                duration: 2000
              })
              const index = this.list.indexOf(idx)
              this.list.splice(idx, 1)
              this.total--
            } else {
              this.$notify({
                title: '失败',
                message: '删除资讯失败',
                type: 'error',
                duration: 2000
              })
            }
          });
        }).catch(() => {
        });

      },
      handleRefresh() {
        this.list = null
        this.total = null
        this.listQuery.pageNo = 1
        this.getList()
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .viewShow {

    /deep/ .el-dialog {
      width: 350px;
      height: 760px;
      padding: 100px 12px;
      border-radius: 50px;
      background: url('../../assets/phone.png') no-repeat;
      background-size: 100% 100%;

      .el-dialog__header {
        padding: 0;
      }

      .el-dialog__body {
        padding: 0;
        background: #fff;
        width: 100%;
        height: 100%;

        .information-cont {
          padding: 0 15px;
          background: #fff;
          white-space: normal;
          word-break: break-all;
          height: 100%;
          overflow-y: auto;

          h3 {
            font-size: 20px;
            line-height: 32px;
            color: #333333;
            font-weight: bold;
            padding-top: 15px;
            margin: 0;

          }

          .smallLine {
            display: flex;
            display: -webkit-flex;
            justify-content: space-between;
            -webkit-justify-content: space-between;
            align-items: center;
            -webkit-align-items: center;
            font-size: 13px;
            color: #BBB;
            padding-top: 20px;
            padding-bottom: 17px;
            border-bottom: 1px solid #E5E8ED;

            .watch {
              padding: 0 0 0 20px;
              font-size: 17px;
              color: #C7C7C7;
            }
          }

          .artical-cont {
            padding-top: 16px;
            font-size: 15px;
            overflow: hidden;

            img {
              width: 100%;
            }
          }

        }

      }

    }

  }

  .el-tag+.el-tag {
    margin-left: 10px;
  }

  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }

  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }

  .app-container {
    padding: 20px;
  }

  .pagination-container {
    margin-top: 30px;
  }

  .widht {
    width: 180px;
  }

  .timeWidht {
    width: 300px;
  }
</style>